<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  <meta name="generator" content="Hugo 0.98.0" />

  
  <meta name="description" content="走在通往幸福的路上">
  

  
  <link rel="apple-touch-icon" sizes="180x180" href="https://blog.v5u.win/apple-touch-icon.png">

  
  <link rel="icon" type="image/png" sizes="32x32" href="https://blog.v5u.win/favicon-32x32.png">

  
  <link rel="icon" type="image/png" sizes="16x16" href="https://blog.v5u.win/favicon-16x16.png">

  
  <link rel="manifest" href="https://blog.v5u.win/site.webmanifest">

  
  <link rel="mask-icon" href="https://blog.v5u.win/safari-pinned-tab.svg" color="">

  <meta name="msapplication-TileColor" content="">

  <meta name="theme-color" content="">

  
  <link rel="stylesheet" href="https://blog.v5u.win/css/bootstrap.min.css" />

  
  <title>docker 安装并使用Redis | 为吾优</title>
  

  <style>
body {
  min-width: 300px;
}

.custom-navbar {
  margin-bottom: 1em;
  height: 60px;
}

.custom-navbar a {
  display: inline-block; 
  padding: 18px 0;
  margin-right: 1em; 
  font-weight: bold; 
}

.custom-navbar a:hover,
.custom-navbar a:focus {
  text-decoration: none; 
}

@media print {
  .custom-navbar {
    display: none;
  }
}

article {
  padding-bottom: 1em;
}

img {
  max-width: 100%;
}


body {
  background-color: #fff;
}



body {
  color: #212529;
}



a {
  color: #007bff;
}



a:hover,
a:focus {
  color: #0056b3;
}



.custom-navbar {
  background-color: #212529;
}



.custom-navbar a {
  color: rgba(255,255,255,.75);
}



.custom-navbar a:hover,
.custom-navbar a:focus {
  color: rgba(255,255,255,1);
}



.container {
  max-width: 800px;
}





</style>
</head>

<body>
  <nav class="custom-navbar">
  <div class="container">
    
    <a href="/">文章</a>
    
    <a href="/tags/">标签</a>
    
    <a href="/about/">关于</a>
    
    <a href="/index.xml">RSS</a>
    
  </div>
</nav>
  
  <div class="container">
    <article>
      <h1>docker 安装并使用Redis</h1>
<p>docker 安装并使用Redis</p>
<ol>
<li>
<p>docker search redis</p>
</li>
<li>
<p>docker pull redis #获得的是lasted版本 redis:3.2</p>
</li>
<li>
<p>配置redis</p>
</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>   mkdir -p /root/redis/data
</span></span><span style="display:flex;"><span>   mkdir -p /root/redis/conf
</span></span><span style="display:flex;"><span>   vi redis.conf
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>   <span style="color:#75715e"># redis.conf</span>
</span></span><span style="display:flex;"><span>   bind 127.0.0.1
</span></span><span style="display:flex;"><span>   protected-mode yes
</span></span><span style="display:flex;"><span>   appendonly no//持久化
</span></span><span style="display:flex;"><span>   <span style="color:#75715e"># requirepass foobared</span>
</span></span></code></pre></div><p>p.s.
protected-mode 是在没有显示定义 bind 地址（即监听全网断），又没有设置密码 requirepass
时，只允许本地回环 127.0.0.1 访问。 也就是说当开启了 protected-mode 时，如果你既没有显示的定义了 bind
监听的地址，同时又没有设置 auth 密码。那你只能通过 127.0.0.1 来访问 redis 服务</p>
<ol start="4">
<li>启动redis</li>
</ol>
<p>命令行启动 <code>docker run -p 6379:6379 --name myredis  -d redis</code></p>
<ol start="5">
<li>测试或debug</li>
</ol>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#75715e"># 查看活跃的容器</span>
</span></span><span style="display:flex;"><span>docker ps
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 如果没有 myredis 说明启动失败 查看错误日志</span>
</span></span><span style="display:flex;"><span>docker logs myredis
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 查看 myredis 的 ip 挂载 端口映射等信息</span>
</span></span><span style="display:flex;"><span>docker inspect myredis
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 查看 myredis 的端口映射</span>
</span></span><span style="display:flex;"><span>docker port myredis	
</span></span></code></pre></div><p>redis 简单使用
进入后台操作系统：redis-cli</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span>$redis-cli
</span></span><span style="display:flex;"><span>redis 127.0.0.1:6379&gt;
</span></span><span style="display:flex;"><span>redis 127.0.0.1:6379&gt; PING
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>PONG
</span></span></code></pre></div>
    </article>
  </div>

  
  
  

  
</body>

</html>